package org.brownflat.watergate.dao;

import org.brownflat.watergate.domain.Group;
import org.hibernate.Criteria;
import org.springframework.stereotype.Repository;

import java.util.List;

import static org.hibernate.criterion.Restrictions.eq;

/**
 * <p>&copy Rupert Jones 2011,2012</p>
 *
 * @author rup
 */
@Repository
public class GroupDAO extends AbstractHibernateDAO<Group> {
    public GroupDAO() {
        super(Group.class);
    }

    public Group findByName(String groupName) {
        Criteria criteria = getCriteria().add(eq("name", groupName));
        return (Group) criteria.uniqueResult();
    }

    @SuppressWarnings("unchecked")
    public List<Group> findDefaultGroups() {
        Criteria criteria = getCriteria().add(eq("defaultGroup", true));
        return (List<Group>) criteria.list();
    }
}
